import { ElMessage, ElMessageBox } from 'element-plus';
import moment from 'moment'
import 'moment/dist/locale/zh-cn'

export function useConfirm (message: string, title: string = '提示', type: 'warning' | 'error' | 'info' | 'success' = 'warning') {
  return new Promise((resolve, reject) => {
    ElMessageBox.confirm(message, title, {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: type,
    }).then(() => {
      resolve(true)
    }).catch(() => {
      
    })
  })
}

export function useMessage (message: string, type: 'warning' | 'error' | 'info' | 'success' = 'success', duration: number = 1000) {
  ElMessage({ type: type, duration: duration, message: message })
}


export function useFormatTime (datetime: string | Date, pattern: string = 'YYYY-MM-DD HH:mm:ss') {
  return moment(datetime).format(pattern)
}

export function useTimeFromNow (time: string | Date) {
  return moment(time).fromNow()
}